package dao;

import java.util.HashMap;
import java.util.Vector;

import sql.CallRawDB;

/*
 * Identifie un plateau de jeu
 */
public class Dungeon {

	public String nameDungeon;

	/**
	 * all the usercharacters present in the dungeon the string is the pseudo,
	 * and the usercharacter is the object, for faster access
	 */
	public HashMap<String, UserCharacter> people;

	/**
	 * the list of rooms which are the parts of the dungeon Hashmap of ID
	 * (integer) and object (Room) for faster access
	 */
	public HashMap<Integer, Room> rooms;

	/**
	 * The pool of servers corresponding to the servers hosting the dungeon
	 */
	public Vector<Server> myServer;

	/**
	 * Constructs a dungeon, with a server
	 * 
	 * @param nameDungeon
	 *            the name of the dungeon
	 * @param myServer
	 *            an initial server hosting the dungeon created
	 */
	public Dungeon(String nameDungeon, Server myServer) {
		this.nameDungeon = nameDungeon;
		this.myServer = new Vector<Server>();
		this.myServer.add(myServer);
		this.people = new HashMap<String, UserCharacter>();
	}

	/*
	 * This function creates the dungeon's rooms It will create a basic dungeon
	 * room table
	 */
	public void createRooms() {
		this.rooms = new HashMap<Integer, Room>();
//		CallRawDB cr = new CallRawDB();
//		try {
		
		// TODO create the final dungeon positions
		Room r0 = new Room(0, this);
		Room r1 = new Room(1, this);
//		Room r2 = new Room(2, this);
//		Room r3 = new Room(3, this);
//		Room r4 = new Room(4, this);
//		Room r5 = new Room(5, this);
//		Room r6 = new Room(6, this);
//		Room r7 = new Room(7, this);
//		Room r8 = new Room(8, this);
//		Room r9 = new Room(9, this);
//		Room r10 = new Room(10, this);
//		Room r11 = new Room(11, this);
//		Room r12 = new Room(12, this);
			
		this.rooms.put(0, r0);	
		this.rooms.put(1, r1);
		
		//System.out.println(this.getRooms().toString());
//		this.rooms.put(2, r2);
//		this.rooms.put(3, r3);
//		this.rooms.put(4, r4);
//		this.rooms.put(5, r5);
//		this.rooms.put(6, r6);
//		this.rooms.put(7, r7);
//		this.rooms.put(8, r8);
//		this.rooms.put(9, r9);
//		this.rooms.put(10, r10);
//		this.rooms.put(11, r11);
//		this.rooms.put(12, r12);
//		this.rooms.get(1).addLink(this.rooms.get(2), "E");
//		this.rooms.get(1).addLink(this.rooms.get(5), "S");
//		this.rooms.get(5).addLink(this.rooms.get(6), "E");
//		this.rooms.get(6).addLink(this.rooms.get(10), "S");
//		this.rooms.get(6).addLink(this.rooms.get(7), "E");
//		this.rooms.get(10).addLink(this.rooms.get(9), "W");
//		this.rooms.get(7).addLink(this.rooms.get(3), "N");
//		this.rooms.get(7).addLink(this.rooms.get(8), "E");
//		this.rooms.get(3).addLink(this.rooms.get(4), "E");
//		this.rooms.get(8).addLink(this.rooms.get(12), "S");
//		this.rooms.get(12).addLink(this.rooms.get(11), "W");
		
		
		//cr.createAllLinks();
		
//		TODO mettre un if pas de room en bd
//		cr.createRoom(r1);
//		cr.createRoom(r2);
//		cr.createRoom(r3);
//		cr.createRoom(r4);
//		cr.createRoom(r5);
//		cr.createRoom(r6);
//		cr.createRoom(r7);
//		cr.createRoom(r8);
//		cr.createRoom(r9);
//		cr.createRoom(r10);
//		cr.createRoom(r11);
//		cr.createRoom(r12);
//		
//		} catch (Exception e1){
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}

	}

	/*
	 * GETTERS AND SETTERS
	 */

	public String getNameDungeon() {
		return nameDungeon;
	}

	public void setNameDungeon(String nameDungeon) {
		this.nameDungeon = nameDungeon;
	}

	public HashMap<String, UserCharacter> getPeople() {
		return people;
	}

	public void setPeople(HashMap<String, UserCharacter> people) {
		this.people = people;
	}

	public HashMap<Integer, Room> getRooms() {
		return rooms;
	}

	public void setRooms(HashMap<Integer, Room> rooms) {
		this.rooms = rooms;
	}

	public Vector<Server> getMyServer() {
		return myServer;
	}

	public void setMyServer(Vector<Server> myServer) {
		this.myServer = myServer;
	}
	
	/**
	 * Get all the monsters of the Dungon, with their Room as Key
	 * @return all the monsters of the dungeon
	 */
	public HashMap<Integer, Monster> getAllMonsters() {
		HashMap<Integer, Monster> res = new HashMap<Integer, Monster>();
		for (int idr : this.rooms.keySet()) {
			Room r = this.rooms.get(idr);
			if (r.getMonster() != null) {
				res.put(idr, r.getMonster());
			}
		}
		return res;
	}

}